package edu.task.controller;

import edu.task.common.base.BaseController;
import edu.task.common.result.RestResult;
import edu.task.model.SysExplain;
import edu.task.model.vo.SysExplainVO;
import edu.task.model.vo.SysRoleVO;
import edu.task.model.vo.SysTaskVO;
import edu.task.service.SysExplainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 个人说明表控制层
 */
@RestController
@RequestMapping("/system/explain")
public class SysExplainController extends BaseController {
    @Autowired
    SysExplainService explainService;

    /**
     * 显示个人说明表所有数据
     */
    @GetMapping("/list")
    public RestResult list() {
        RestResult ajax = RestResult.success();
        ajax.put(RestResult.DATA_TAG, explainService.selectExplainList());
        return ajax;
    }

    /**
     * 个人说明新增
     */
    @PostMapping
    public RestResult add(@RequestBody SysExplainVO explain) {
        boolean flag = explainService.insertExplain(explain);
        return toAjax(flag ? 1 : 0);
    }

    /**
     * 删除个人说明
     */
    @DeleteMapping("/{ExplainId}")
    public RestResult remove(@PathVariable Long ExplainId){
        return toAjax(explainService.deleteExplainById(ExplainId));
    }

    /**
     * 修改新增个人说明
     */
    @PutMapping
    public RestResult edit(@Validated @RequestBody SysExplainVO explain) {
        boolean flag = explainService.updateExplain(explain);
        return toAjax(flag ? 1 : 0);
    }

    /**
     * 根据数组删除个人说明
     */
    @DeleteMapping("/List")
    public RestResult remove2(@RequestBody SysExplainVO sysExplain){
        Long[] ExplainIds = sysExplain.getExplainIds();
        return toAjax(explainService.deleteExplainByIds(ExplainIds));
    }

    /**
     * 根据用户ID显示个人说明表所有数据
     */
    @GetMapping("/list/{userId}")
    public RestResult index(@PathVariable(value = "userId", required = false) Long userId){
        RestResult ajax = RestResult.success();
        ajax.put(RestResult.DATA_TAG, explainService.selectExplainListByUserId(userId));
        return ajax;
    }

}
